package com.glsc.ngateway.common.base.domain.mysql.cmdb;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;


@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@Where(clause = "is_delete = 0")
@SQLDelete(sql = "update t_cmdb_device_detail set is_delete = 1 where id=?")
@Data
@Entity
@Table(name = "t_cmdb_device_detail")
public class CmdbDeviceDetail {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "device_detail_id")
    private Integer deviceDetailId;

    @Column(name = "device_detail_code", length = 100)
    private String deviceDetailCode;

    @Column(name = "device_standard_code", length = 100)
    private String deviceStandardCode;

    @Column(name = "name", length = 100)
    private String name;

    @Column(name = "assert_num", length = 100)
    private String assertNum;

    @Column(name = "assert_id", length = 100)
    private String assertId;

    @Column(name = "brand", length = 100)
    private String brand;

    @Column(name = "model", length = 100)
    private String model;

    @Column(name = "sn", length = 100)
    private String sn;

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @JsonSerialize(using = LocalDateSerializer.class)
    @JsonDeserialize(using = LocalDateDeserializer.class)
    @Column(name = "manufact_date")
    private LocalDate manufactDate;

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @JsonSerialize(using = LocalDateSerializer.class)
    @JsonDeserialize(using = LocalDateDeserializer.class)
    @Column(name = "expirate_date")
    private LocalDate expirateDate;

    @ManyToOne
    @JoinColumn(name = "device_type_id", insertable = false, updatable = false)
    private CmdbDeviceType deviceType;

    @Column(name = "device_type_id")
    private Integer deviceTypeId;

    @Column(name = "life_status")
    private Integer lifeStatus;

    @JsonProperty("uAmount")
    @Column(name = "u_amount")
    private Integer uAmount;

    @Column(name = "cpu_port_amount")
    private Integer cpuPortAmount;

    @Column(name = "memory_port_amount")
    private Integer memoryPortAmount;

    @Column(name = "disk_port_amount")
    private Integer diskPortAmount;

    @Column(name = "pci_port_amount")
    private Integer pciPortAmount;

    @Column(name = "ele_port_amount")
    private Integer elePortAmount;

    @Column(name = "memory_total_capacity")
    private Integer memoryTotalCapacity;

    @Column(name = "machine_room_id")
    private Integer machineRoomId;

    @Column(name = "machine_cabinet_id")
    private Long machineCabinetId;

    @Column(name = "machine_cabinet_u_id")
    private Long machineCabinetUId;

    @Column(name = "input_price_with_tax")
    private BigDecimal inputPriceWithTax;

    @Column(name = "input_price_no_tax")
    private BigDecimal inputPriceNoTax;

    @Column(name = "user", length = 100)
    private String user;

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @JsonSerialize(using = LocalDateSerializer.class)
    @JsonDeserialize(using = LocalDateDeserializer.class)
    @Column(name = "purchase_date")
    private LocalDate purchaseDate;

    @Column(name = "is_delete", nullable = true, columnDefinition = "int DEFAULT '0' COMMENT '是否删除，0未删除，1 已删除'")
    private Integer isDelete;

    @OneToMany
    @Where(clause = " life_status=1 and is_delete = 0  ")//on中的过滤条件
    @JoinColumn(referencedColumnName = "device_detail_id",name = "location_id",foreignKey = @ForeignKey(name = "none",value = ConstraintMode.NO_CONSTRAINT))
    private List<CmdbCpuDetail> cmdbCpudetail;

    @OneToMany
    @Where(clause = " life_status=1 and is_delete = 0  ")//on中的过滤条件
    @JoinColumn(referencedColumnName = "device_detail_id",name = "location_id",foreignKey = @ForeignKey(name = "none",value = ConstraintMode.NO_CONSTRAINT))
    private List<CmdbMemoryDetail> cmdbMemoryDetail;

    @OneToMany
    @Where(clause = " life_status=1 and is_delete = 0  ")//on中的过滤条件
    @JoinColumn(referencedColumnName = "device_detail_id",name = "location_id",foreignKey = @ForeignKey(name = "none",value = ConstraintMode.NO_CONSTRAINT))
    private List<CmdbDiskDetail> cmdbDiskDetail;

    @OneToMany
    @Where(clause = " life_status=1 and is_delete = 0 ")//on中的过滤条件
    @JoinColumn(referencedColumnName = "device_detail_id",name = "location_id",foreignKey = @ForeignKey(name = "none",value = ConstraintMode.NO_CONSTRAINT))
    private List<CmdbPartDetail> cmdbPartDetail;

    @Transient
    private CmdbDeviceStandard cmdbDeviceStandard;
    // getters and setters
}

